home *** CD-ROM | disk | FTP | other *** search
/ Double-Click / Double Click - Issue 1 (Pentrisoft).adf / Mag1 / SpriteMove.doc < prev    next >
Text File  |  1996-07-20  |  4KB  |  52 lines

  1. <H2><B>Sprite Movement</B>
  2. <H3>
  3. In this section, I am going to explain how to create a moving image of a sprite. The language I use is AMOSPro, but I will try to keep things general.
  4.  
  5. The first thing is to create some images to work with. In AMOS, you can use the Object Editor; see your user manual regarding other languages. Even at this early stage, you must give some consideration to the final screen resolution and colours. Here are some things to bear in mind:
  6.  
  7.   - AMOSPro, as standard, cannot support AGA screen modes, so you are limited to 32 colours (16 in hires). If your language does support up to 256 colours, bear in mind that more colours means slower speed, which will reduce the number of things you can have happening (eg, number of enemies on screen at once).
  8.   - A 320x256 resolution screen will usually be fine. A 640x256 or 640x512 screen will give much better graphics, but will slow things dramatically down, and so aren't recommened for arcade games.
  9.  
  10. After choosing you resolution, draw a simple image of a spaceship, or something. Graphics drawn at this stage are often called `Mock-Up' graphics due to their simplistic appearance, and aren't usually changed until the end of a game's development, in case things need to be changed.
  11.  
  12. Now you are ready to start programming proper. You must have two variables for the ship's x and y coordinates on the screen, just like on a graph. The x coordinates run left to right, starting at 0, and going to the maximum (depends on the screen resolution). The y coordinates run from the top of the screen to the bottom (remember that!). I will call my variables SHIP_X and SHIP_Y, and will use a 320x256 resolution. I'll also need a variable called SPEED for the number of pixels to be moved by the ship each time. Here is some code:
  13.  
  14.   Double Buffer  -  Needed for double buffering; I'll explain later
  15.   SHIP_X=160
  16.   SHIP_Y=128   }  -  Set Variables
  17.   SPEED=2
  18.   Bob 1,SHIP_X,SHIP_Y,1  -  Draw image; I'm actually using Bobs, not Sprites; see later
  19.   Do  -  Repeat indefinitely
  20.      If Joy(1)<AL><AR>0  -  Has Joystick been moved...
  21.         If Jup(1)=-1 and SHIP_Y<AR>0  -  ...up?
  22.            Add SHIP_Y,-SPEED  -  Subtract SPEED from SHIP_Y
  23.         Else If Jdown(1)=-1 and SHIP_Y<AL>256  -  ...down?
  24.            Add SHIP_Y,SPEED
  25.         Endif
  26.         If Jleft(1)=-1 and SHIP_X<AR>0  -  ...left?
  27.            Add SHIP_X,-SPEED  -  Subtract SPEED from SHIP_X
  28.         Else If Jright(1)=-1 and SHIP_X<AL>320  -  ...right?
  29.            Add SHIP_X,SPEED
  30.         Endif
  31.         Bob 1,SHIP_X,SHIP_Y,1  -  Redraw image
  32.      Endif
  33.   Loop  -  End of loop
  34.  
  35. Double buffering means that two images are used for the screen. The screen is redrawn on one while the other is displayed, then they are swapped around. This is important to remember when using bobs, but not when using sprites. AMOS does this swapping automatically after you've used the Double Buffer command, but I don't know about other languages.
  36.  
  37. Bobs and sprites are two different ways that the Amiga displays images on screen. Here are the basic differences between them.
  38.  
  39.   -  Bobs share the same resolution and number of colours as the screen, where as sprites are independant of the screen.
  40.   -  Sprites are restricted to 16 colours for pre-AGA screen modes (I don't know about AGA ones). There are also restrictions on their number, size, and position on screen, but you can have as many bobs as you want.
  41.   -  Sprites can be used in HAM and HAM8 modes (that's the 4096/262144 colour modes), but bobs cannot.
  42.   -  Sprites tend to be faster than bobs.
  43.  
  44. Confused? Don't worry; for beginners, I recommend you stick entirely with bobs, as they are easier to use and program with. In reality, however, the best results are achieved using a combination of the two, usually bobs for larger images such as spaceships, and sprites for smaller, faster moving images like missiles.
  45.  
  46. Also note when the joystick position is checked, I check whether the ship is not already at the edge of the screen (eg, for moving 
  47. left, SHIP_X must be greater than 0).
  48.  
  49. That's it for now... in the next issue, I'll hopefully explain about how to fire missiles, among other stuff.
  50.  
  51. <H2><B>Mark Harman</B>
  52.